-
Notifications
You must be signed in to change notification settings - Fork 68
Add Windows terminal backend support #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Introduces WindowsTerminal for PowerShell-based command execution on Windows systems. Updates factory and init logic to conditionally import and use platform-specific terminal backends, ensuring compatibility across Windows and Unix-like platforms.
xingyaoww
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should rename the tool execute_bash into execute_terminal because of the powershell here? 🤔
And we tell the agent if it is using powershell vs bash. But we can do this in subsequent pr
Simplifies the code by unconditionally importing fcntl and pty, removing the platform-specific logic and dummy assignments for Windows. This module is intended for Unix-like systems only.
Deleted scripts/demo.py as it is no longer needed. The demo script previously demonstrated basic usage of the OpenHands SDK and agent setup.
Eliminated an erroneous 'n' character from the import block in terminal_session.py to clean up the code and prevent potential syntax errors.
Changed assertions in test_windows_terminal_close_and_reopen to check 'obs.text' instead of 'obs.output' for command results. This aligns the test with the updated observation object structure.
|
@SmartManoj can you resolve merge conflicts/ |
Update the terminal module's __init__.py to conditionally import WindowsTerminal on Windows and SubprocessTerminal/TmuxTerminal on other platforms. This change ensures only relevant terminal classes are exposed based on the operating system.
Removed the deprecated execute_bash.terminal package and updated all relevant imports to use the new openhands.tools.terminal.terminal structure. This change consolidates terminal-related code under a single module for improved maintainability and clarity.
|
[Automatic Post]: This PR seems to be currently waiting for review. @ryanhoangt, could you please take a look when you have a chance? |
ryanhoangt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR. When testing the PR on the examples/01_hello_world.py and adjusting the message to something like "Please check the current directory, list all files and then exit.", I saw it first attempted to run a bash command with &&, which failed in PowerShell. However, it didn't fail instantly, it got stuck in soft timeout observation loop and the agent decided to reset the terminal. Do you have any ideas why it happened?
| ] | ||
| # Conditionally import platform-specific terminals | ||
| if platform.system() == "Windows": | ||
| from openhands.tools.terminal.terminal.windows_terminal import WindowsTerminal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why we export things conditionally like this? I think it might break several test files like tests/tools/terminal/test_session_factory.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else, it will raise ModuleNotFoundError: No module named 'fcntl'
https://github.com/OpenHands/OpenHands/issues/11629
| logger.info("Using forced TmuxTerminal") | ||
| terminal = TmuxTerminal(work_dir, username) | ||
| return TerminalSession(terminal, no_change_timeout_seconds) | ||
| elif terminal_type == "subprocess": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since SubprocessTerminal depends on fcntl which isn't available on Windows, should we add a if platform.system() == "Windows": check here and raise RuntimeError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 86 will run only when terminal_type== "subprocess" is specified and None is the default value for that.
Does this tool description need to be updated?
|
Yes we should either phrase it so the description is general enough, OR we should implement a switch (i.e., only change the description if windows is selected as the terminal implementation) |
Introduces TOOL_DESCRIPTION_FOR_WINDOWS for PowerShell commands and updates TerminalTool to select the appropriate description based on the platform. This improves clarity and guidance for users on both Unix and Windows systems.
ryanhoangt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great and LGTM, thank you!
xingyaoww
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanhoangt, can we potentially get LLM-back integration tests running on Windows as well? Maybe in a subsequent PR
| --cov-report=term-missing ` | ||
| --cov-fail-under=0 ` | ||
| --cov-config=pyproject.toml ` | ||
| tests/tools/terminal/test_windows_terminal.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we run all the tests here instead of just the terminal one?
Ideally we should check all things are working on Windows (maybe just skip subprocess/tmux terminals).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1209 - Follow up
Deleted the [tool.coverage.paths] section, which specified source paths for coverage analysis. This simplifies the configuration and may indicate a change in how coverage is managed or reported.
|
Pre-requisite #1014? |
Are the failing tests browser tests? That PR only refers to the browser tool. |
|
When I look at the failed github action, I see 69 tests failed: Seems like file editor tests are failing, not just browser? |
tests/tools/file_editor/conftest.py
Outdated
| yield file_path | ||
| # On Windows, files may be locked briefly after handles are closed. | ||
| # This is due to Windows file system behavior where file handles may not be | ||
| # immediately released, opportunistic locks (oplocks), or background processes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this affect other behaviors too, not just current tests? 🤔
Deleted the [tool.coverage.report] section and its ignore_errors setting from pyproject.toml, likely to simplify coverage configuration or rely on defaults.
Moved the Unix and Windows terminal tool descriptions to separate template files and updated the code to load them dynamically. This improves maintainability and allows easier updates to the descriptions without modifying the Python source.
Renamed unix and windows terminal description templates from .txt to .j2 for consistency with Jinja2 template naming. Updated references in definition.py and included the new template files in the agent-server.spec data collection.
|
[Automatic Post]: It has been a while since there was any activity on this PR. @SmartManoj, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
1 similar comment
|
[Automatic Post]: It has been a while since there was any activity on this PR. @SmartManoj, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. |
xingyaoww
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually @SmartManoj could we combine #1209 with this PR - so we can be sure the windows terminal is working as expected before we merge it? Thanks!
|
I'm happy to unblock that issue. I think there is a bit of a discussion in the related issue on how exactly we design the code. |




Introduces
WindowsTerminalfor PowerShell-based command execution on Windows systems. Updatesfactoryandinitlogic to conditionally import and use platform-specific terminal backends, ensuring compatibility across Windows and Unix-like platforms.